package homework;

import java.io.*;

public class Test3 {
    public static void main(String[] args) throws IOException {
        File dir = new File(".");
        File[] subs = dir.listFiles(f -> f.isFile());
        for (File sub: subs){
             String filename = sub.getName();
            System.out.println(filename);
            int index = filename.lastIndexOf(".");
            if (index == -1){
                index = filename.length();
            }
             filename = new StringBuilder(filename).insert(index, "_cp").toString();
           FileInputStream fis = new FileInputStream(sub);
           FileOutputStream fos = new FileOutputStream(filename);
           int d ;
           byte[] data = new byte[1024*10];
           while((d = fis.read(data)) != -1){
               fos.write(data,0,d);
           }
            fis.close();
           fos.close();


        }

    }
}
